<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@ page isELIgnored="false"%>
<html>
	<head>
		<title>考核方案-第一步定制方案-SJH</title>
	</head>
<e:View id="eView" designProperty="width: 1024; height: 768">
	<script type="text/javascript">SkinUtil.getSkin();</script>
	<script type="text/javascript">SkinUtil.getModuleSkin();</script>	
	<script type="text/javascript" src="<c:url value='/js/perform/perform.js'/>"></script>
	
	<div id="Invisual Controls" style="min-height: 40px;">
	<!-- 考核方案  -->
		<e:Dataset id="Dataset_project" pageSize="-1">
			<e:Field name="projectId" dataType="string" label="考核方案ID" maxLength="32" />
			<e:Field name="projectName" dataType="string" label="考核方案名称" maxLength="100" required="true"/>
			<e:Field name="systemId" dataType="string" label="指标体系ID" maxLength="32"  dropDown="DataDropDown_indexSysName" required="true"/>
			<e:Field name="cycleId" dataType="string" label="考核周期ID" maxLength="32" />
			<e:Field name="segmentType" dataType="string" label="分段类型" maxLength="32" dropDown="ListDropDown_segmentType"/>
			<e:Field name="startDate" dataType="date" label="开始日期" maxLength="7" />
			<e:Field name="endDate" dataType="date" label="结束日期" maxLength="7" />
			<e:Field name="projectDesc" dataType="string" label="方案说明" maxLength="200" />
			<e:Field name="remark" dataType="string" label="备注" maxLength="400" />
			<e:Field name="createTime" dataType="date" label="创建时间" maxLength="7" readOnly="true"/>
			<e:Field name="createUserId" dataType="string" label="创建人ID" maxLength="32" readOnly="true"/>
			<e:Field name="createUserName" dataType="string" label="创建人" maxLength="100" readOnly="true"/>
			<e:Field name="createOrgId" dataType="string" label="创建机构ID" maxLength="32" readOnly="true"/>
			<e:Field name="createOrgName" dataType="string" label="创建机构" maxLength="100" readOnly="true"/>
			<e:Field name="orgLevelCode" dataType="string" label="机构级次" maxLength="100" readOnly="true" visible="false"/>			
			<e:Field name="updateUserId" dataType="string" label="修改人ID" maxLength="32" visible="false"/>			
			<e:Field name="updateUserName" dataType="string" label="修改人" maxLength="100" readOnly="true"/>
			<e:Field name="updateTime" dataType="date" label="修改时间" maxLength="7" readOnly="true"/>				
			<e:Field name="cycleName" dataType="string" label="考核周期名称" />
		</e:Dataset> 
	<!--考核阶段 -->
		<e:Dataset id="Dataset_project_segment" pageSize="-1" readOnly="true">
			<e:Field name="projectId" dataType="string"/>
			<e:Field name="cycleId" label="考核阶段编码" dataType="string"/>
			<e:Field name="segmentName" label="考核阶段名称" dataType="string"/>
			<e:Field name="startDate" label="开始日期" dataType="date"/>
			<e:Field name="endDate" label="结束日期" dataType="date"/>
		</e:Dataset>
	<!-- 考核方案-指标 -->
		<e:Dataset id="Dataset_project_index" pageSize="-1">
			<e:Field name="projectId" dataType="string"/>
			<e:Field name="indexId" dataType="string"/>
			<e:Field name="indexType" dataType="string"/>
			<e:Field name="indexName" dataType="string" label="指标名称"/>
		</e:Dataset>
	<!-- 指标体系ID-对应名称 -->
		<e:Dataset id="Dataset_indexSys" pageSize="-1">
			<e:Field name="systemId" dataType="string"/>
			<e:Field name="systemName" dataType="string"/>
		</e:Dataset>
		
		<e:DataDropDown id="DataDropDown_indexSysName" dataset="Dataset_indexSys"
			visibleFields="systemName" codeField="systemId" textField="systemName" showColumnHeader="false" fixed="true" 
			onAfterSelect="DataDropDown_indexSysName_onAfterSelect()">
		</e:DataDropDown>
	<!-- 分段方式 -->
		<e:ListDropDown id="ListDropDown_segmentType" fixed="true" autoDropDown="true" onAfterSelect="ListDropDown_segmentType_onSelect()" >
			<e:ListDropDownItem name="item0" value="" label="无"/>
			<e:ListDropDownItem name="item1" value="HALFYEAR" label="半年"/>
			<e:ListDropDownItem name="item2" value="QUARTER" label="季"/>
			<e:ListDropDownItem name="item3" value="MONTH" label="月"/>
		</e:ListDropDown>
	  
	<!-- 获取分段,指标,指标权重 -->
		<e:Command id="Command_loadPageData" action="com.longtop.perform.khyg.web.ProjectManageAction" method="loadPageData" showHintInfoOnSuccess="false">
			<e:DatasetInfo name="info1" dataset="Dataset_indexSys" alwayRefreshClient="true" submitType="none"/>
			<e:DatasetInfo name="info3" dataset="Dataset_project_index" alwayRefreshClient="true" submitType="none"/>
			<e:Parameter name="projectId" dataType="string" value="${param.projectId}"/>
		</e:Command>
	<!-- 获取考核分段 -->
		<e:Command id="Command_querySegment" action="com.longtop.perform.khyg.web.ProjectManageAction" method="querySegment" showHintInfoOnSuccess="false">
			<e:DatasetInfo name="info1" dataset="Dataset_project_segment" submitType="none" alwayRefreshClient="true"/>
			<e:Parameter name="cycleUnit" dataType="string"/>
			<e:Parameter name="startDate" dataType="string"/>
			<e:Parameter name="endDate" dataType="string"/>
		</e:Command>
	<!-- 保存方案： -->
		<e:Command id="Command_save" action="com.longtop.perform.khyg.web.ProjectManageAction" method="saveProject" onExecuteSuccess="Command_save_onSuccess(command)">
			<e:DatasetInfo name="info1" dataset="Dataset_project" submitType="current" alwayRefreshClient="true"/>
			<e:DatasetInfo name="info2" dataset="Dataset_project_index" submitType="all"/>
			<e:DatasetInfo name="info3" dataset="Dataset_project_segment" submitType="all"/>
			<e:Parameter name="task" value=""></e:Parameter><!-- 修改Or新增 -->
		</e:Command>
	  
		<e:LookupDropDown id="LookupDropDown_chooseIndex"	path="jsp/perform/zb/system/systemDropdown.jsp" windowWidth="420"windowHeight="380" 
			fixed="true" autoDropDown="true" onSelect="LookupDropDown_chooseIndex_onSelect(dropdown,iframe,text)"
			windowCaption="选择指标数据">
		</e:LookupDropDown> 
		<e:LookupDropDown id="LookupDropDown_chooseCyc" path="jsp/perform/kh/cycle/cycleDropdown.jsp" windowWidth="500" windowHeight="230"
			fixed="true" autoDropDown="true" onAfterSelect="LookupDropDown_chooseCyc_onSelect(dropdown,iframe,text)"
			windowCaption="选择周期" alwaysRefresh="true">
		</e:LookupDropDown> 
	</div>

<body style="overflow: auto">
<e:Page id="ePage" action="com.longtop.perform.khyg.web.ProjectManageAction" onAfterLoadPage="ePage_onAfterLoadPage()" onBeforeLoadPage="ePage_onBeforeLoadPage()">
  <table style="width: 100%; height:100%;" border="0" cellpadding="2" cellspacing="2">
    <tr>
       <td align="center" valign="top">
         <e:GroupBox id="GroupBox" style="height:100%; width:100%; " caption="员工考核方案信息">
         <div style="height:95%">
           <table id="tab" border="0" cellpadding="3" cellspacing="3"  width="95%" align="center">
			<tr>
              <td align="right" width="85">
                <e:Label id="Label_projectName" caption="考核方案名称"/>
              </td>
              <td align="left">
                <e:Text id="projectName" dataset="Dataset_project" field="projectName" style="width:320px" />
              </td>
            </tr>
            <tr>
              <td align="right" width="85">
                <e:Label id="Label_cycleName" caption="考核周期"/>
              </td>
              <td>
                <e:Text id="cycleName" dataset="Dataset_project" field="cycleName" style="width:160px" readOnly="true" required="true"/>&nbsp;
                <e:Button id="Button_cycle" caption="..." style="width:25px;height:18px;font-weight:bold"
                        onClick="Button_cycle_onClick()"/>
              （即，从:<e:Text id="startDate" dataset="Dataset_project" field="startDate"  style="width:95px" readOnly="true"/>
                到:<e:Text id="endDate" dataset="Dataset_project" field="endDate"  style="width:95px" readOnly="true"/> ）
              </td>
            </tr><tr>
              <td align="right" width="85" valign="top">
                <e:Label id="Label_projectDesc" caption="考核方案说明"/>
              </td>
              <td align="left">
                <e:Text id="projectDesc" editorType="textArea" dataset="Dataset_project" field="projectDesc" style="height:40px; width: 480px; "/>
              </td>
            </tr><tr>
              <td align="right" width="85">
               	<e:Label id="Label_systemId" caption="指标体系"/>
              </td>
              <td align="left">
                <e:Text id="systemId" dataset="Dataset_project" field="systemId"  style="width:260px" />
              </td>
            </tr><tr>
              <td align="right" width="85" valign="top">
                <font color="red">*</font>&nbsp;<e:Label id="Label5" caption="考评指标"/>
              </td>
              <td>
                <table><tr>
                  <td>
                    <select id="index_combox" multiple  style="width:260px;height:100px"></select>
                  </td><td>
                    <e:Button id="Button_chooseIndex" caption="选择指标..." style="width:80px" onClick="Button_chooseIndex_onClick()"/><BR><BR>
                    <e:Button id="Button_removeIndex" caption="移除指标..." style="width:80px" onClick="Button_removeIndex_onClick()"/>
                  </td>
                </tr></table>
              </td>
            </tr>
            <tr>
              <td align="right" width="80">分段方式</td>
              <td align="left">
                <e:Text id="segmentType" dataset="Dataset_project"  field="segmentType" style="width:80px" readOnly="true"/>
              </td>
            </tr>
            <tr id="tr_segment" style='display:block; overflow:auto'>
              <td align="right" width="85" valign="top">&nbsp;</td>
              <td>
                <e:Grid id="Grid1" dataset="Dataset_project_segment" style="width:480px;height:160px" showIndicator="false" designProperty="overflow:auto">
                  <e:Column name="segmentName" field="segmentName" style="width:230"/>
                  <e:Column name="startDate" field="startDate" style="width:110"/>
                  <e:Column name="endDate" field="endDate" style="width:110"/>
                </e:Grid>
              </td>
            </tr><tr>
              <td align="right" width="85">备 注</td>
              <td align="left">
                <e:Text id="remark" dataset="Dataset_project" field="remark"  style="height:50px; width:480px; " editorType="textArea"/>
              </td>
            </tr>
          </table>
          <table border="0" cellpadding="0" cellspacing="2" width="95%" align="center">
            <tr>
              <td align="center" height="32" colspan="2" bgcolor="#E8EFFB">
                <e:Button id="Button_submit" caption="保存方案" icon="/images/submit.gif" onClick="Button_submit_onClick()"/>
              </td>
            </tr>
          </table>
        </div>
        </e:GroupBox>
      </td>
    </tr>
  </table>
</e:Page>
</body>
<script language="Javascript">
	var projectId = '${param.projectId}';
	var index_combox;//指标集合
	//init:
	function ePage_onBeforeLoadPage(){
		//设置窗口位置
		LookupDropDown_chooseCyc.setWindowTop(10);
		LookupDropDown_chooseCyc.setWindowLeft(200);
	
	    //是否是修改方案：
	    if(!isEmpty(projectId)){
			updateInit();
	    }
	    		
	    index_combox = document.getElementById("index_combox");//指标集合
	    halfYear = ListDropDown_segmentType.getItemByValue('HALFYEAR');
	    quarter = ListDropDown_segmentType.getItemByValue('QUARTER');
	    month = ListDropDown_segmentType.getItemByValue('MONTH');
	    none = ListDropDown_segmentType.getItemByValue('');
	}
	//修改方案初始化设置
	function updateInit(){
		//更新父窗口projectId和projectName
		parent.$J("Text_projectId").setValue(Dataset_project.getValue("projectId"));
		parent.$J("Text_projectName").setValue(Dataset_project.getValue("projectName"));
	    Command_save.parameters.setValue("task","update");//设置保存机构的事件为修改
	   	Button_cycle.disabled = 'true';
	   	systemId.readOnly = 'true';	
	}
	//数据初始化：
	function ePage_onAfterLoadPage(){
		isShowSegment(Dataset_project.getValue("segmentType"));//是否显示分段
		//获取指标与分段数据：
		Command_loadPageData.execute();
		$J("systemId").render();
		if(!isEmpty(projectId)){//若是编辑窗口则加载数据：
			//考核分段：
			var parameters = $J("Command_querySegment").parameters;
		    parameters.setValue("cycleUnit", $J("segmentType").getValue());
		    parameters.setValue("startDate", $J("startDate").getDisplayValue());
		    parameters.setValue("endDate", $J("endDate").getDisplayValue());
		   	Command_querySegment.execute();
		    //方案对应指标集合-填充到combBox：
		    var tmpRecord = Dataset_project_index.getFirstRecord();
		    while(tmpRecord != null){
		    	addOption(index_combox, tmpRecord.getValue("indexName"), tmpRecord.getValue("indexId"));
	       		tmpRecord = tmpRecord.getNextRecord();
			}
		}
	}
	//是否显示分段：
	function isShowSegment(segmentType){
	    if(isEmpty(segmentType)){
	    	document.getElementById("tr_segment").style.display = 'none';
	    }else{
	    	document.getElementById("tr_segment").style.display = 'block';
	    }
	}
	/*选择指标体系下拉框*/
	function DataDropDown_indexSysName_onAfterSelect(){
	    clearOption(index_combox);
	}
	//单击移除指标：
	function Button_removeIndex_onClick(){
		if(index_combox.selectedIndex<0){
			MsgBox.showWarnMsg("请选中一条指标。");
			return;
		}
		index_combox.remove(index_combox.selectedIndex);
	}
	
	//单击选择指标：
	function Button_chooseIndex_onClick(){
		var indexSys = $J("systemId").getValue();
		if(isEmpty_JSon(indexSys)){
			MsgBox.showWarnMsg("请选择指标体系。");
			return;
		}
		var systemId = $J("systemId").getValue();
		var systemName = Util.encode($J("systemId").getDisplayValue());
		var path = "jsp/perform/zb/system/systemDropdown.jsp?systemId="+systemId+"&systemName="+systemName;
		LookupDropDown_chooseIndex.setPath(path,true);
		LookupDropDown_chooseIndex.open();
	}
	//选择指标：
	function LookupDropDown_chooseIndex_onSelect(dropdown,iframe,text){
		var tree = iframe.$J("indexTree");
		var node;
		var selectedNodes = tree.getSelectedNodes();
		for(var i=0;i<selectedNodes.length;i++) {
		   node = selectedNodes[i];
		   if (node.record && !node.hasChildren()) {//(node.record && !node.hasChildren()) //hasChildren()仅对非延迟加载有效
		   	   var indexName = node.record.getValue("nodeName");
		   	   var indexId = node.record.getValue("nodeId");
		       //alert(node.record.getValue("nodeName"));//得到选中结点引用记录的数据
	            addOption(index_combox,indexName,indexId); 
		   }
		}
	}
	
	/*点击选择考核周期*/
	function Button_cycle_onClick(){
		LookupDropDown_chooseCyc.open();
	    Dataset_project.setValue("segmentType","");
	    Dataset_project_segment.clearData();
	}
	//选择考核周期：
	function LookupDropDown_chooseCyc_onSelect(dropdown,iframe,text){
		var Dataset_planCyc = iframe.Dataset_cycle;
		if(!Dataset_project.currentRecord){
			Dataset_project.insertRecord();
		}
		Dataset_project.disableControls();
		try {
			Dataset_project.setValue("cycleId",Dataset_planCyc.getValue("cycleId"));	
			Dataset_project.setValue("cycleName",Dataset_planCyc.getValue("segmentName"));
			Dataset_project.setValue("startDate",Dataset_planCyc.getValue("startDate"));
			Dataset_project.setValue("endDate",Dataset_planCyc.getValue("endDate"));	
		}finally {
			Dataset_project.enableControls();
			Dataset_project.refreshControls();
		}
		//处理分段:
		var cycleUnit = Dataset_planCyc.getValue("cycleUnit") ;
		showSegment(cycleUnit);
	}
	//处理分段:
	function showSegment(cycleUnit){
		 if (cycleUnit == 'QUARTER'){
			 $J('segmentType').setReadOnly(false);
			 ListDropDown_segmentType.removeItem(halfYear);
			 ListDropDown_segmentType.removeItem(quarter);
		}else if (cycleUnit == 'HALFYEAR'){
			 $J('segmentType').setReadOnly(false);
			 ListDropDown_segmentType.removeItem(halfYear);
		}else if (cycleUnit == 'YEAR'){
			 ListDropDown_segmentType.clear();
			 ListDropDown_segmentType.addItem(none);			 
			 ListDropDown_segmentType.addItem(halfYear);
			 ListDropDown_segmentType.addItem(quarter);
			 ListDropDown_segmentType.addItem(month);
			 $J('segmentType').setReadOnly(false);
		}
	}

	/*选择分段方式*/
	function ListDropDown_segmentType_onSelect(dropdown,item,text){
		isShowSegment(text.getValue());
		//考核分段：
	    var parameters = $J("Command_querySegment").parameters;
	    parameters.setValue("cycleUnit", $J("segmentType").getValue());
	    //alert(item.getValue()+","+$J("startDate").getDisplayValue()+","+$J("endDate").getDisplayValue());
	    parameters.setValue("startDate", $J("startDate").getDisplayValue());
	    parameters.setValue("endDate",$J("endDate").getDisplayValue());
	    Command_querySegment.execute();
	}
	//提交方案
	function Button_submit_onClick(){
		//组装考核方案对应的指标到Dataset_project_index:
	    var items = index_combox.options;
	    if (items.length == 0){
	        MsgBox.showWarnMsg("关联指标不能为空，请选择指标。");
	        return;
	    }else{
	        Dataset_project_index.clearData();
			Dataset_project_index.disableControls();
			try {
		        for(var i=0;i<items.length;i++){
		            var record = Dataset_project_index.insertRecord();
		            record.setValue("indexId",items[i].value);
		        }
			}finally {
				Dataset_project_index.enableControls();
				Dataset_project_index.refreshControls();
			}
	    }
	   	Command_save.execute();
	}
	//保存方案成功后：
	function Command_save_onSuccess(command){
		updateInit();//改成修改方案状态
	}

</script>
</e:View>
</html>